package cn.com.cetccst.compliancecheck.demo.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

import cn.com.cetccst.compliancecheck.demo.R;

public class TextListDlg extends AlertDialog.Builder {

    public static void show(Context context, String[] texts, final DialogInterface.OnClickListener listener) {
        new TextListDlg(context).setAdapter(new TextListAdapter(context, texts), listener).show();
    }

    private TextListDlg(@NonNull Context context) {
        super(context);
    }

    private static class TextListAdapter extends ArrayAdapter<String> {
        public TextListAdapter(Context context, String[] labelList) {
            super(context, R.layout.string_item, labelList);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.string_item, parent,
                        false);
            }
            ((TextView) convertView).setText(getItem(position));
            return convertView;
        }
    }
}
